<!-- html -->
<template>
  <h2 class="h2">{{ title }}</h2>
  <span class="span3">父组件</span>
  <br>
  <span class="span2">内容：{{ text }}</span>
  <button class="button1" @click="changeText">修改内容</button>
  <hr class="hr1">
  <span class="span3">子组件</span>
  <br>
  <provideInjectTest1Child />
</template>

<!-- js或ts -->
<script lang="ts">
export default {
  name: 'provideInjectTest1'
}
</script>

<!-- js或ts -->
<script setup lang="ts">
import { ref, provide } from 'vue'
import provideInjectTest1Child from '@/components/componenttransmit/ProvideInjectTest1Child.vue'
//数据
let title = ref('provide + inject，父组件=>子组件=>孙组件')
let text = ref('hello')
//方法
function changeText() {
  text.value += '-'
}
//向外部提供属性
provide('parentText', { text, changeText })
</script>

<!-- 样式 -->
<style scoped></style>